#encoding:utf8 
import time

from handlers.gamefunc import * 
from handlers.configs import * 
from baseEntity import baseEntity

class gmaeScene(baseEntity):

	def __init__(self , cfg):
		self._data = dict(
			w = cfg["width"],
			h = cfg["height"],
			mapv = FuncScene.getSceneMap(cfg["cfgfile"]),
			maxinclude = cfg["maxnum"],
			crttime = time.time(),
			)

		self.pnum = 0  		  #玩家数量
		self.players = set() #玩家集合


	def add_player(self , playerobj):
		if self.pnum < self._data["maxinclude"]:
			self.players.add(playerobj)
			self.pnum = self.pnum + 1
			return 0 
		return 1

	def remove_player(self , playerobj):
		try:
			self.players.discard(playerobj)
			self.pnum = self.pnum - 1
			return 0
		except:
			return 1

	def get_scenedata(self):
		ret = dict(
			nownum = self.pnum,
			data = self._data
			)
		return ret 